package com.zerui.manager.icc.strategy.command;

import com.alibaba.cola.exception.BizException;
import com.zerui.manager.icc.service.AccessControlInfoService;
import com.zerui.manager.icc.strategy.CommandStrategy;
import com.zerui.manager.web.cmd.DeviceOperateDoorCmd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

@Slf4j
@Component
public class RemoteOpenDoor extends CommandBase implements CommandStrategy {

    @Resource
    private AccessControlInfoService accessControlInfoService;

    @Override
    public void execute(DeviceOperateDoorCmd cmd) {
        Set<String> channelCodes = this.getChannelCodes(cmd.getDeviceIds());
        try {
            accessControlInfoService.openDoor(channelCodes.toArray(new String[channelCodes.size()]));
        } catch (Exception e) {
            log.error("向ICC门禁开门指令出错", e);
            throw new BizException("ICC不支持开门指令", e);
        }
    }
}
